package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/8 09:37
 * @description
 */
public class Code238 {
    public int[] productExceptSelf(int[] nums) {
        int total = 1;
        int flag = 0;
        int place = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                flag++;
                place = i;
            } else {
                total *= nums[i];
            }
        }
        if (flag == 1) {
            for (int i = 0; i < nums.length; i++) {
                if (place == i) {
                    nums[i] = total;
                } else {
                    nums[i] = 0;
                }
            }
        } else if (flag > 1) {
            for (int i = 0; i < nums.length; i++) {
                nums[i] = 0;
            }
        } else {
            for (int i = 0; i < nums.length; i++) {
                nums[i] = total / nums[i];
            }
        }
        return nums;
    }
}
